$(function () {
    obj.init();
});

var obj = new function() {
    return {
        addGradeForm: null,
        form: null,
        init: function () {
            this.addGradeForm = $('#addGrade_form');
            this.form = new xhForm(this.addGradeForm);
            this.funObj().addDataAction();
            this.listener();
        },
        listener: function () {
            var $this = this;
            this.addGradeForm.find('input[name=grade]').bind('click', function(){
                if(this.checked){//选中时单选
                    $('#addGrade_form').find("input[name=grade]").not(this).attr("checked", false);
                }
            });
            $('#bt_modal_confirm',parent.document).click(function () {
                $this.funObj().saveData();
            });
        },
        funObj: function () {
            return {
                addDataAction: function () {
                    str = '';
                    if (outIds !== null && JSON.stringify(outIds) !== '[]'){
                        $.each(outIds, function (value, name) {
                            str += '<label style="width: fit-content">' +
                                '<input type="checkbox" name="grade" value="' + value + '">'+ '<span style="padding-right: 60px">'+ name +'</span>' +
                                '</label>';
                        });
                    } else {
                        str = '<label style="width: fit-content">不存在剩余年级</label>';
                    }
                    $('#grade_list').append($(str));
                },
                saveData: function () {
                    obj = $('input[name=grade]:checked');
                    var grade = obj.val();
                    var name = obj.next().html();
                    if (grade === '' || grade === null || grade === undefined){
                        window.top.xhTop.showError('不存在或请选择一个');
                        xhExtra.setBtnNormal($('#bt_modal_confirm',parent.document));
                        return false;
                    }
                    xhExtra.setBtnNormal($('#bt_modal_confirm',parent.document));
                    window.top.xhTop.closeModal();
                    window.top.xhTop.getActiveFrame().frames['bookVerFrame'].obj.funObj().addGradeData(grade, name, id, length, type, groupId, subject, version);
                }
            }
        }
    }
};
